<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    /*
      需求：小张(男生)给小李(美女)送礼物,送礼物这个过程让小孙(小张的狐朋狗友)代替小张完成
    */

    // 创建接受礼物的小李这个类
    var Girl = function (name) {
      this.name = name;
    };

    // 创建送礼的小张同学这个类
    var Boy = function (girl) {
      //传递的girl为一个对象
      this.girl = girl;
      this.sendGift = function (gift) {
        console.log("Hi" + this.girl.name + "这是小张送给你的礼物" + gift);
      };
    };

    // 代理操作：小孙代小张完成送礼物给小李
    var ProxyBoy = function (girl) {
      this.girl = girl;
      this.sendGift = function (gift) {
        // var zhang = new Boy(girl);
        // zhang.sendGift(gift);
        new Boy(girl).sendGift(gift);
      };
    };

    var xiaoSun = new ProxyBoy(new Girl("美美同学"));
    xiaoSun.sendGift("999朵玫瑰");
  </script>
</html>
